<!DOCTYPE html>
<html lang="en">
<?php
session_start();
if (!isset($_SESSION['state'])) {
  header("Location: ../../bbs/views/login.php");
  exit();
}
// 判断登录的是是不是管理员
if ($_SESSION['role'] == 'user') {
  header("Location: ../../bbs/views/login.php");
}

?>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>后台首页-什么都论坛</title>
</head>
<style>
  * {
    margin: 0;
    padding: 0;
  }

  body {
    background: #eee;
  }

  .head {
    width: 100%;
    height: 80px;
    display: flex;
    background: rgb(244, 244, 244);
    overflow: hidden;
    border-top: 2px solid #0327B3;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  }

  .logo {
    width: 30%;
    height: 80px;
  }

  .logo img {
    width: 192px;
    margin: 10px 0 0 10px;
  }

  h1 {
    width: 40%;
    text-align: center;
    margin-top: 10px;
    color: #0327B3;
  }

  .root {
    width: 30%;
    margin-top: 10px;
    margin-left: 30px;
    display: flex;
    justify-content: flex-end;
  }

  .root-head {
    width: 60px;
    height: 60px;
    margin-right: 10px;
  }

  .root-head>img {
    width: 100%;
    height: 100%;
    border: 2px solid #000;
    border-radius: 50%;
  }

  .root-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    margin-right: 10px;
    color: #0327B3;
  }

  .root-name {
    max-width: 100px;
    font-size: 16px;
    font-weight: 600;
    padding: 5px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .root-info button {
    width: 80px;
    height: 30px;
    background: rgb(255, 0, 0);
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.5s ease;
  }

  .root-info button:hover {
    background: #0327B3;
  }

  .root-info button a {
    color: #fff;
    text-decoration: none;
    font-size: 14px;
  }

  /* 导航条 */

  .nav {
    width: 100%;
    height: 50px;
    background: transparent;
    float: left;
    border-top: 1px solid #ccc;
    margin: 0 auto;
    margin-top: 8px;
  }

  .nav ul {
    list-style: none;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
  }

  .nav ul li {
    width: 220px;
    height: 100%;
    border-radius: 10px;
    text-align: center;
    line-height: 50px;
    cursor: pointer;
    transition: all 0.5s ease;
  }

  .nav ul li a {
    width: 100%;
    height: 100%;
    display: block;
    color: #0327B3;
    text-decoration: none;
  }

  .nav ul li:hover {
    background: #5085CB;
  }

  .nav ul li:hover a {
    color: #fff;
  }

  .now {
    background: rgb(159, 196, 244);
  }

  .nowa {
    color: #000 !important;
  }

  /* 主体 */
  .content {
    width: 100%;
  }

  .left {
    width: 20%;
    height: 100vh;
    float: left;
    position: fixed;
    top: 145px;
    left: 0;
    background: #F4F6F9;
    background-image: url("../image/miku-二次元少女 .png");
    background-size: cover;
    background-position: center;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
    z-index: 2;
    padding-top: 30px;
  }

  .left ul {
    list-style: none;
    padding: 0 10px;
  }

  .left ul li {
    width: 90%;
    background: rgba(255, 255, 255, 0.7);
    transition: background 0.3s, box-shadow 0.3s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    padding: 10px 0 10px 15px;
    border-bottom: 4px solid #000;
    cursor: pointer;
    position: relative;
  }

  .left ul li:first-child {
    border-radius: 8px 8px 0 0;
  }

  .left ul li:last-child {
    border-bottom: 0px;
    border-radius: 0 0 8px 8px;
  }

  .left ul li:hover:not(.left-info) {
    background: #5085CB;
    color: #fff;
    box-shadow: 0 4px 16px rgba(80, 133, 203, 0.15);
  }

  .left ul li span {
    float: right;
    font-size: 16px;
    color: #888;
    margin-right: 8px;
    transition: transform 0.3s, color 0.3s;
    user-select: none;
    font-weight: 400;
  }

  /* 鼠标悬停时箭头旋转 */
  .left ul li:hover>span {
    color: #000;
    transform: rotate(90deg);
  }

  /* 下拉菜单样式 */
  .left ul li .left-info {
    width: 80%;
    max-height: 0;
    overflow: hidden;
    background: #fff;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 16px rgba(80, 133, 203, 0.08);
    transition: max-height 0.3s, padding 0.3s;
    border: 1px solid #e0e0e0;
    border-top: none;
    margin-top: 2px;
    padding: 0;
  }

  .left ul li .left-info a {
    display: block;
    padding: 8px 0 8px 24px;
    color: #0327B3;
    font-size: 15px;
    font-weight: 400;
    text-decoration: none;
    border-bottom: 1px solid #f0f0f0;
    background: transparent;
    transition: all 0.2s, color 0.2s, padding-left 0.2s;
    letter-spacing: 1px;
  }

  .left ul li .left-info a:last-child {
    border-bottom: none;
  }

  .left ul li .left-info a:hover {
    background: #f0f6ff;
    color: #5085CB;
    padding-left: 32px;
    border-radius: 4px;
    font-weight: 500;
  }

  /* 悬停时显示下拉菜单 */
  .left ul li:hover .left-info {
    max-height: 200px;
    padding: 10px 15px;
    color: #0327B3;
  }

  .left ul li>a {
    color: #0327B3;
    font-size: 17px;
    font-weight: 600;
    text-decoration: none;
    transition: color 0.3s;
    padding-right: 10px;
  }

  .left ul li>a {
    display: inline-block;
    width: 93%;
    height: 100%;
    box-sizing: border-box;
  }



  .right {
    width: 79%;
    height: calc(100vh - 145px);
    background-image: url("../image/bg.png");
    background-size: cover;
    background-position: center;
    float: left;
    position: fixed;
    top: 145px;
    right: 0;
    z-index: 0;
    text-align: center;
    display: block;
    overflow-y: auto;
    padding-top: 60px;
    box-sizing: border-box;
  }

  .right h2,
  .right p {
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(80, 133, 203, 0.08);
    padding: 18px 32px;
    margin-bottom: 18px;
    width: 80%;
    max-width: 800px;
    color: #0327B3;
    font-weight: 500;
    letter-spacing: 1px;
    margin: 0 auto;
  }

  .right h2 {
    font-size: 30px;
    text-align: center;
    margin-top: 0;
    margin-bottom: 24px;
    color: #1a3e7a;
    font-weight: 700;
  }
</style>

<body>
  <!-- 头部 -->
  <div class="head">
    <div class="logo">
      <img src="../image/logo.png" alt="">
    </div>
    <h1>后台管理系统</h1>
    <div class="root">

      <div class="root-head">
        <img src="<?php
        if (isset($_SESSION['head'])) {
          echo '../image/' . $_SESSION['head'];
        } else {
          echo '../image/1.gif';
        }
        ?>" alt="userhead" onerror='this.onerror=null; this.src="../image/1.gif";'>
      </div>
      <div class="root-info">
        <span class="root-name">
          <?php
          echo $_SESSION['username'];
          ?>
        </span>
        <?php
        echo <<<EOF
             <button>
             <a href="../../bbs/control/doLogin.php?action=logout" onclick="confirm('确认退出登录吗？')">退出登录</a>
             </button>
EOF;
        ?>
      </div>
    </div>
  </div>
  <!-- 导航条 -->
  <div class="nav">
    <ul>
      <?php

      if (isset($_GET['action']) && $_GET['action'] == 'user') {
        echo '<li><a href="./indexBms.php">首页</a></li>
      <li class="now"><a href="./indexBms.php?action=user"  class="nowa">用户管理</a></li>
      <li><a href="./indexBms.php?action=post">帖子管理</a></li>
      <li><a href="./indexBms.php?action=comment">评论管理</a></li>
      <li><a href="./indexBms.php?action=setting">系统设置</a></li>
    </ul>';
      } else if (isset($_GET['action']) && $_GET['action'] == 'post') {
        echo '<li ><a href="./indexBms.php">首页</a></li>
      <li ><a href="./indexBms.php?action=user"  class="nowa">用户管理</a></li>
      <li class="now"><a href="./indexBms.php?action=post"  class="nowa">帖子管理</a></li>
      <li><a href="./indexBms.php?action=comment">评论管理</a></li>
      <li><a href="./indexBms.php?action=setting">系统设置</a></li>
    </ul>';
      } else if (isset($_GET['action']) && $_GET['action'] == 'comment') {
        echo '<li ><a href="./indexBms.php">首页</a></li>
      <li ><a href="./indexBms.php?action=user"  >用户管理</a></li>
      <li ><a href="./indexBms.php?action=post"  >帖子管理</a></li>
      <li class="now"><a href="./indexBms.php?action=comment" class="nowa">评论管理</a></li>
      <li><a href="./indexBms.php?action=setting">系统设置</a></li>
    </ul>';
      } else if (isset($_GET['action']) && $_GET['action'] == 'setting') {
        echo '<li ><a href="./indexBms.php">首页</a></li>
      <li ><a href="./indexBms.php?action=user"  >用户管理</a></li>
      <li ><a href="./indexBms.php?action=post"  >帖子管理</a></li>
      <li ><a href="./indexBms.php?action=comment" >评论管理</a></li>
      <li class="now"><a href="./indexBms.php?action=setting" class="nowa">系统设置</a></li>
    </ul>';
      } else {
        echo '<li class="now"><a href="./indexBms.php" class="nowa">首页</a></li>
      <li><a href="./indexBms.php?action=user">用户管理</a></li>
      <li><a href="./indexBms.php?action=post">帖子管理</a></li>
      <li><a href="./indexBms.php?action=comment">评论管理</a></li>
      <li><a href="./indexBms.php?action=setting">系统设置</a></li>
    </ul>';
      }

      ?>
      
    </ul>
  </div>
  <!-- 主体 -->
  <div class="content">
    <!-- 左侧菜单 -->
    <div class="left">
      <ul>
        <li>
          <a href="./indexBms.php" >首页</a>
          <span>></span>
          <div class="left-info">
            <a href="../../bbs/views/index.php">前往用户首页</a>            
          </div>
        </li>
        <li>
          <a href="./indexBms.php?action=user">用户管理</a>
          <span>></span>
          <div class="left-info">
            <a href="./indexBms.php?action=user">用户列表</a>
            <a href="./indexBms.php?action=user" onclick="alert('请选择编辑的用户')">用户编辑</a>
            <a href="./indexBms.php?action=user" onclick="alert('请选择删除的用户')">用户删除</a>
          </div>
        </li>
        <li>
          <a href="./indexBms.php?action=post">帖子管理</a>
          <span>></span>
          <div class="left-info">
            <a href="./indexBms.php?action=post">帖子列表</a> 
            <a href="./indexBms.php?action=post&board=1">版块列表</a> 
            <a href="./indexBms.php?action=post" onclick="alert('请选择删除的帖子')">帖子删除</a>
          </div>
        </li>
        <li>
          <a href="./indexBms.php?action=comment">评论管理</a>
          <span>></span>
          <div class="left-info">
            <a href="./indexBms.php?action=comment">评论列表</a>            
            <a href="./indexBms.php?action=comment" onclick="alert('请选择删除的评论')">评论删除</a>
          </div>
        </li>
        <li>
          <a href="./indexBms.php?action=setting">系统设置</a>
          <span>></span>
          <div class="left-info">
            <a href="./indexBms.php?action=setting&role=change">权限设置</a>
            <a href="./indexBms.php?action=setting">管理员设置</a>
          </div>
        </li>
      </ul>
    </div>
    <!-- 主要内容 -->
    <div class="right">
      <?php
      if (isset($_GET['action'])) {
        $action = $_GET['action'];
        // 去除其他的class=nowa
        echo "<script>document.querySelector('.nav ul li.nowa').classList.remove('nowa');</script>";
        switch ($action) {
          case 'user':
            include_once '../views/userBms.php';
            break;
          case 'edit':
            include_once '../views/editUserBms.php';
            break;
          case 'post':
            include_once '../views/postBms.php';
            break;
          case 'comment':
            include_once '../views/replyBms.php';
            break;
          case 'setting':
            include_once '../views/setBms.php';
            break;
          default:
            include_once '../views/indexBms.php';
            break;
        }
      } else {
        echo '<div class="right-home">
        <h2>欢迎使用后台管理系统</h2>
        <p>这里是后台管理系统的主要内容，你可以在这里进行任何操作，包括添加、编辑、删除、审核等。</p>
        <p>你可以在左侧菜单栏中选择相应的功能模块，进行相应的操作。</p>
        <p>祝你使用愉快！</p>
        </div>';
      }
      ?>


    </div>
  </div>
</body>
<script>

  // 左侧菜单栏点击事件
</script>

</html>